﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace NetCoreEFMySqlApi.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class testController : ControllerBase
    {
        private readonly DataContext Con;

        public testController(DataContext context)
        {
            this.Con = context;
        }

        // POST api/test/{json}
        // 增
        [HttpPost]
        public IEnumerable<test> Post(test test)
        {
            Con.Add(test);

            var count = Con.SaveChanges();
            
            return Con.Test;
        }

        // GET api/test/{id}
        // 查
        [HttpGet("{id}")]
        public IEnumerable<test> Get(int id)
        {

            Con.Database.EnsureCreated();
            var testEnity = Con.Test.SingleOrDefault(s => s.id == id);
            List<test> testEnitys = new List<test>();
            testEnitys.Add(testEnity);
            return testEnitys;
        }
    }
}